$(function(){
    /**
     *  @author yys
     *  Description:  添加权限页面提交到后台
     *  @date  10:00 2018-01-15
     */
    $("#form-menu-add").validate({
        rules: {
            name: {
                required: true,
                minlength: 2,
                maxlength: 16
            },
            path: {
                required: true,
                minlength: 2,
                maxlength: 40
            },
            remarks: {
                required: false
            },
        },
        onkeyup: false,
        focusCleanup: true,
        success: "valid",
        submitHandler:function(form){
            var pId = $("#pId").val();
            var name = $("#name").val();
            var path = $("#path").val();
            var remarks = $("#remarks").val();
            var params = { pId:pId, name:name, path:path, remarks:remarks};
            $.ajax({
                type: "POST",
                url: '/menu/addMenu',
                dataType : 'json',
                data: params,
                success: function (data) {
                    var  result = eval(data);
                    if (data.success == true) {
                        layer.msg(data.msg,{icon:1,time:2000},function(){
                            parent.location.reload();
                            //注意: 关闭打开的添加页 无法实现刷新 现修改为刷新父页面
                            // var index = parent.layer.getFrameIndex(window.name);
                            // parent.$('.btn-refresh').click();
                            // parent.layer.close(index);
                        });
                    } else if(data.success == false){
                        layer.msg(data.msg,{icon:2,time:4000});
                        return;
                    }
                }
            });
        }
    });
});